<!--
 * @Description: 账户变动审核
 * @Author: Liulian
 * @Date: 2021-06-24 17:16:30
 * @LastEditors: Morgan
 * @LastEditTime: 2021-07-02 19:54:21
-->
<template>
  <!-- 账户变动审核 -->
  <div>
    <!-- 模糊搜索 -->
    <div class="search">
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <el-date-picker
          v-model="searchForm.Time"
          value-format="timestamp"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right"
        />
        <el-form-item>
          <el-select
            v-model="searchForm.applyType"
            placeholder="请选择类型"
            clearable
          >
            <el-option label="充值" value="充值" />
            <el-option label="提现" value="提现" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="searchForm.status"
            placeholder="请选择状态"
            clearable
          >
            <el-option label="未审核" value="未审核" />
            <el-option label="通过" value="通过" />
            <el-option label="不通过" value="不通过" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="searchForm.userId"
            placeholder="申请人编号"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 消息 -->
    <div>
      <el-table v-loading="loading" stripe :data="tableData" style="width: 100%">
        <el-table-column label="序号" type="index" align="center" />
        <el-table-column prop="userId" label="申请人编号" align="center" />
        <el-table-column prop="applyTime" label="申请时间" align="center">
          <template slot-scope="scope">
            {{ moment(scope.row.commentTime).format("YYYY-MM-DD HH:mm:ss") }}
          </template>
        </el-table-column>
        <el-table-column prop="applyType" label="变更类型" align="center" />
        <el-table-column prop="money" label="变更资金" align="center">
          <!-- ￥<span class="red_info_money" slot-scope="scope">{{scope.row.money}}</span>元 -->
          <template slot-scope="scope">
            ￥<span class="red_info_money">{{ scope.row.money }}</span>元
          </template>
        </el-table-column>
        <el-table-column prop="reason" label="变更原因" align="center" />
        <el-table-column prop="status" label="状态" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === '通过'" type="success">{{
              scope.row.status
            }}</el-tag>
            <el-tag v-else-if="scope.row.status === '不通过'" type="danger">{{
              scope.row.status
            }}</el-tag>
            <el-tag v-else type="info">{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <a
              v-if="scope.row.status == '未审核'"
              type="text"
              class="green_info"
              @click.prevent="toChengeStatus(scope.row, '通过')"
            >通过</a>
            <a
              v-if="scope.row.status == '未审核'"
              type="text"
              class="warning_info"
              @click.prevent="toChengeStatus(scope.row, '不通过')"
            >不通过</a>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="pagination-div">
      <el-pagination
        :current-page="params.page"
        :page-sizes="[2, 5, 10, 15, 20]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import {
  pageQueryAccountApply,
  checkPass,
  checkNoPass
} from '@/api/accountApply'
export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      searchForm: {},
      // 表格展示的数据
      tableData: [],
      // 分页参数
      params: {
        page: 1,
        pageSize: 10
      },
      // 总条数
      total: 0,
      // 加载
      loading: false
    }
  },
  computed: {},
  watch: {
    params: {
      handler() {
        this.queryData()
      },
      deep: true
    }
  },
  created() {
    // 发请求
    this.queryData()
  },
  mounted() {},
  methods: {
    moment,
    // 获取分页账号变更数据
    async queryData() {
      this.loading = true
      // const res = await pageQuery({ page: 1, pageSize: 100 })
      const temp = {
        // 合并数据
        ...this.params,
        ...this.searchForm
      }
      // 遍历对象
      for (const key in temp) {
        // key是一个变量，代表的属性名
        // console.log(key, temp[key]);
        if (!temp[key]) {
          delete temp[key]
        }
      }
      if (temp.Time) {
        temp.beginTime = temp.Time[0]
        temp.endTime = temp.Time[1]
        delete temp.Time
      }
      // console.log(temp);
      const res = await pageQueryAccountApply(temp)
      this.loading = false
      this.tableData = res.data.list
      this.total = res.data.total
    },
    toSearch() {
      this.queryData()
    },
    // 审核
    async toChengeStatus(row, status) {
      const temp = {
        id: row.id
      }
      const res = {}
      if (status == '通过') {
        const res = await checkPass(temp)
      } else {
        const res = await checkNoPass(temp)
      }
      this.$notify.success({
        title: '成功',
        message: res.message
      })
      this.queryData()
    },
    // 每页显示的条数发生变化时的处理程序
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`)
      // this.params.pageSize = val;
      // this.params.page = 1;
      this.params = {
        pageSize: val,
        page: 1
      }
    },
    // 当前页码发生变化时的事件处理程序
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`)
      this.params.page = val
    }
  }
}
</script>
<style scoped>
</style>
